#!/bin/bash

echo "🚀 启动Python知识图谱系统"
echo "================================"

# 检查Python版本
python_version=$(python3 --version 2>&1)
echo "📍 Python版本: $python_version"

# 激活虚拟环境
if [ -d "venv" ]; then
    echo "🔧 激活虚拟环境..."
    source venv/bin/activate
else
    echo "❌ 虚拟环境不存在，请先运行: python3 -m venv venv"
    exit 1
fi

# 检查依赖
echo "📦 检查依赖包..."
pip list | grep -i flask > /dev/null
if [ $? -ne 0 ]; then
    echo "📥 安装依赖包..."
    pip install -r requirements.txt
fi

# 初始化数据库
if [ ! -f "knowledge_graph.db" ]; then
    echo "🗄️ 初始化数据库..."
    python init_db.py
fi

# 启动应用
echo "🌟 启动Web服务器..."
echo "📊 访问地址: http://localhost:5000"
echo "👤 管理员账户: admin / admin123"
echo "================================"
echo ""

python app.py